Each PPM image consists of the following:

1.   A "magic number" for identifying the file type. A ppm image's magic number is the two characters "P6".

2.   Whitespace (blanks, TABs, CRs, LFs).

3.   A width, formatted as ASCII characters in decimal.

4.   Whitespace.

5.   A height, again in ASCII decimal.

6.   Whitespace.

7.   The maximum color value (Maxval), again in ASCII decimal. Must be less than 65536 and more than zero.

8.   A single whitespace character (usually a newline).

9.   A raster of Height rows, in order from top to bottom. Each row consists of Width pixels, in order from left to right. Each pixel is a triplet of red, green, and blue samples, in that order. Each sample is represented in pure binary by either 1 or 2 bytes. If the Maxval is less than 256, it is 1 byte. Otherwise, it is 2 bytes. The most significant byte is first.

A row of an image is horizontal. A column is vertical. The pixels in the image are square and contiguous.